package com.jnshu.service.impl;

import com.jnshu.controller.UpLoadPhoto;
import com.jnshu.service.UpLoadPhotoService;
import com.jnshu.tools.AliyunUtilImage;
import com.jnshu.tools.resultUtils.RUtil;
import com.jnshu.tools.resultUtils.ResultBean;
import lombok.extern.java.Log;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName UpLoadPhotoServiceImpl
 * @Descrintion
 * @Author bd
 * @Date 2019/8/6 22:47
 * @Version 1.0
 **/
@Service
@Log
public class UpLoadPhotoServiceImpl implements UpLoadPhotoService {
    @Override
    public ResultBean image(MultipartFile file) {
        log.info("feign传过来的图片名字为：" + file.getOriginalFilename() + "图片类型为" + file.getContentType());

        try {
            String fileName = file.getOriginalFilename();
            AliyunUtilImage aliyunUtilImage = new AliyunUtilImage();
            String url = aliyunUtilImage.upLoad(file, fileName);
            return RUtil.ok(url);
        } catch (Exception e) {
            e.printStackTrace();
            return RUtil.error(300, "图片上传失败");
        }
    }
}
